package im.elephas.androfan.common.widget;

import im.elephas.androfan.R;
import im.elephas.androfan.activity.AndroFanActivity;
import im.elephas.androfan.activity.PersonalInfoActivity;
import im.elephas.androfan.fanfouapi.items.StatusItem;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.ViewGroup;

public class MyStatusWidget extends StatusWidget {
	
	public MyStatusWidget(ViewGroup parentView, AndroFanActivity mActivity) {
		super(parentView, mActivity);
		super.setWidgetView(mActivity.getLayoutInflater().inflate(
				R.layout.statusesmyitem, null));
		initViews();
		getWidgetView().setBackgroundColor(Color.argb(100, 181, 202, 115));
	}
	
	public MyStatusWidget(ViewGroup parentView, AndroFanActivity mActivity,
			StatusItem si) {
		this(parentView, mActivity);
		setStatusItem(si);
	}
	
	protected void showDialog() {
		Builder dialog = new AlertDialog.Builder(mActivity);
		String[] sel = { "删除", "收藏", "查看资料" };
		dialog.setTitle("对自己");
		dialog.setItems(sel, new Dialog.OnClickListener() {

			@Override
			public void onClick(DialogInterface dialog, int which) {
				Intent i;
				Bundle b;
				switch (which) {
				case 0:
					getApiCaller().deleteMyStatus(statusItem);
					setInvisible();		
					break;
				case 1:
					getApiCaller().createFavoriteStatus(statusItem);
					break;
				case 2:
					i = new Intent(getActivity(), PersonalInfoActivity.class);
					b = new Bundle();
					b.putSerializable("item", statusItem.getUser());
					i.putExtras(b);
					getActivity().startActivityForResult(i, 0);
					break;
				default:
					break;
				}
			}
		});
		dialog.show();
	}	
}
